// 手机号码校验
export const validatePhone = (rule, value, callback) => {
  let phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
  if (value == "") {
    callback(new Error("请输入手机号码"));
    return;
  }
  if (!phoneReg.test(value)) {
    callback(new Error("手机号码格式有误"));
  } else {
    callback();
  }
};
// 密码校验
export const validatePass = (rule, value, callback) => {
  let pessReg = /^[a-zA-Z0-9_-]{6,18}$/;
  if (!value) {
    callback(new Error("请输入密码"));
    return;
  }
  if (!pessReg.test(value)) {
    callback(new Error("密码格式有误"));
  } else {
    callback();
  }
};

// 格式化时间
/**
 * params  time(14位时间戳)
 * return yyyy年MM月dd日
 *
 */
export const validateTime = (time) => {
  let date = new Date(time);
  let y = date.getFullYear();
  let M = date.getMonth() + 1;
  let d = date.getDate();
  M = M > 10 ? M : "0" + M;
  d = d > 10 ? d : "0" + d;
  return `${y}-${M}-${d}`;
};
